/**
 * 
 */
package com.gragra.wilsHandler;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
/**
 * @author Christoph Teichmann
 * 26.09.2013
 */
public class Evaluate
{
	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException
	{
		DoubleArrayList accs = new DoubleArrayList();
		DoubleArrayList unAccs = new DoubleArrayList();
		for(int i=1;i<args.length;++i)
		{
			BufferedReader gold = new BufferedReader(new FileReader(args[0]));
			BufferedReader eval = new BufferedReader(new FileReader(args[i]));
			double[] pair = EvaluateDependencyMicroAveraged.main(gold, eval);
			accs.add(pair[0]);
			unAccs.add(pair[1]);
		}
		double mean;
		System.out.println("accuracy");
		System.out.println(mean = makeMean(accs));
		System.out.println(makeVariance(mean,accs));
		System.out.println("undirected accurracy");
		System.out.println(mean = makeMean(unAccs));
		System.out.println(makeVariance(mean,unAccs));
	}
	/**
	 * 
	 * @param mean
	 * @param accs
	 * @return
	 */
	private static double makeVariance(double mean, DoubleArrayList accs)
	{
		double ret = 0.0;
		for(int i=0;i<accs.size();++i)
		{ret += Math.pow(accs.getDouble(i)-mean, 2.0);}
		return ret/(double) accs.size();
	}
	/**
	 * 
	 * @param accs
	 * @return
	 */
	private static double makeMean(DoubleArrayList accs)
	{
		double ret = 0.0;
		for(int i=0;i<accs.size();++i)
		{ret += accs.getDouble(i);}
		return ret/(double) accs.size();
	}
}